﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QuanLyThuNgan
{
    public class FormHelpers
    {
        /// <summary>
        /// Kiem tra xem mot form con co mo roi hay chua
        /// </summary>
        /// <param name="nameChildForm"></param>
        /// <param name="fMDI"></param>
        /// <returns></returns>
        public static Form CheckChildFormShow(string nameChildForm, Form fMDI)
        {
            foreach (Form f in fMDI.MdiChildren)
            {
                if (f.Name == nameChildForm)
                    return f; //form con nay dang show
            }
            return null; //form con nay chua co mo
        }

        /// <summary>
        /// Kiem tra mot form con co mo roi hay chua tu mot form con khac
        /// </summary>
        /// <param name="nameChildForm"></param>
        /// <param name="fMDI"></param>
        /// <returns></returns>
        public static Form CheckChildFormShow_Child(string nameChildForm, Form fMDI)
        {
            foreach (Form f in fMDI.ParentForm.MdiChildren)
            {
                if (f.Name == nameChildForm)
                    return f; //form con nay dang show
            }
            return null; //form con nay chua co mo
        }

        public static void ResetButton(bool change, Control ctrl)
        {
            if (ctrl is Button || ctrl is SimpleButton)
            {
                if (change == true)
                {
                    ctrl.Enabled = false;
                    if (ctrl.Name == "btnSave" || ctrl.Name == "btnCancel")
                        ctrl.Enabled = true;
                }
                if (change == false)
                {
                    ctrl.Enabled = true;
                    if (ctrl.Name == "btnSave" || ctrl.Name == "btnCancel")
                        ctrl.Enabled = false;
                }
            }
            foreach (Control i in ctrl.Controls)
            {
                ResetButton(change, i);
            }
        }

        public static void ResetForm(Control ctrl)
        {
            if ((ctrl is TextBox) || (ctrl is System.Windows.Forms.ComboBox) || (ctrl is DateTimePicker) || (ctrl is BaseEdit))
            {
                if(!(ctrl is CheckEdit))
                    ctrl.ResetText();

            }
            foreach (Control i in ctrl.Controls)
            {
                ResetForm(i);
            }
        }

        public static string CreateCode(DateTime dt, string name)
        {
            string code = string.Empty;
            string[] tmp = dt.ToString("yyyy-MM-dd HH:mm:ss").Split(' ');
            code = name + tmp[0].Replace("-", "") + tmp[1].Replace(":", "");
            return code;
        }

        public static string strMaHang = string.Empty;
        public static string strMaNV = string.Empty;
        public static string strQuyen = string.Empty;
        public static string strTenNV = string.Empty;
        public static int intTongTien = 0;
        public static int intIn = 0; //khong in chi luu thoi

        public static bool changeDonVi = false;
        public static bool changeNhom = false;
        public static bool changeVatTu = false;
        public static bool changeAnPham = false;
        public static bool changeKhachHang = false;
        public static bool changeMayIn = false;
        public static bool changeTonKho = false;
        public static bool changeNhaCungCap = false;

    }
}
